const moment = require('moment');

class TimeTool {

  getDate(num = 0) {
    let now = new Date().getTime();
    let date = moment(now - (1000 * 60 * 60 * 24 * num)).format('YYYY-MM-DD');
    return date;
  }

  getDays(date) {
    let start = new Date(date).getTime();
    let now = new Date().getTime();
    let days = parseInt((now - start) / (1000 * 60 * 60 * 24));
    return days;
  }
  getNowDate(){

    let nowDate=new Date().getTime();
    let date=moment(nowDate).format('YYYY-MM-DD HH:mm:ss');
    return date
  }

  getEachMonthDays(year){

    let monthStartAndEnd=[]
    for (let m =1;m<=12;m++){
        let firstDay = new Date(year, m - 1, 1);
        let firstDayFormat=moment(firstDay).format('YYYY-MM-DD');
        let lastDay = new Date(year, m, 0);
        let lastDayFormat=moment(lastDay).format('YYYY-MM-DD');

        monthStartAndEnd.push({
          m:m,
          firstDay:firstDayFormat,
          lastDay:lastDayFormat
        })

    }

    return monthStartAndEnd


  }
 
}






module.exports = new TimeTool();